<template>
  <div>
    <!-- table -->
    <el-table :data="msbdList" border style="width: 100%" height="400">
      <el-table-column type="index" label="#" width="50"> </el-table-column>
      <el-table-column prop="title" label="标题">
        <template slot-scope="scope">
          <el-link type="primary" :underline="false" @click="look(scope.row)">{{
            scope.row.title
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="cid"
        :formatter="(row) => classifyMap[row.cid]"
        label="分类"
        width="120"
      >
      </el-table-column>
      <el-table-column prop="author" label="作者" width="120">
      </el-table-column>
      <el-table-column prop="time" label="用时" width="50"> </el-table-column>
      <el-table-column prop="date" label="发布时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="220">
        <template slot-scope="scope">
          <el-button
            type="warning"
            size="small"
            @click="handelUpdatemsbd(scope.row)"
            >修改</el-button
          >
          <el-button
            type="danger"
            size="small"
            @click="handelDelmsbd(scope.row.id)"
            >删除</el-button
          >
          <el-button type="info" size="small">导出</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapState, mapGetters, mapMutations } from "vuex";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions("msbdList", ["getMsbdlist", "delMsbdlist", "upDateMsbdlist"]),
    ...mapMutations("msbdList", ["SET_FORM","SET_DRAWER"]),
    // 查看
    look(row){
      this.SET_FORM(row)
      this.SET_DRAWER(this.drawer)
    },
    // 修改
    handelUpdatemsbd(row) {
      console.log(row);
      this.SET_FORM ({ ...row });
      this.SET_DRAWER(this.drawer)
    },
    // 删除
    async handelDelmsbd(id) {
      await this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.delMsbdlist(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  computed: {
    ...mapGetters("msbdList", ["classifyMap"]),
    ...mapState("msbdList", ["msbdList","drawer"]),
  },
  mounted() {
    this.getMsbdlist();
  },
};
</script>

<style scoped>
</style>